﻿using DGSFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;

namespace Framework.Resources
{
    /// <summary>
    /// Summary description for GetHoseIndex
    /// </summary>
    public class GetHoseIndex : IHttpHandler
    {
        DGSFrameworkEntities entity = new DGSFrameworkEntities();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
            var status = 0;
            var data = new dgs_HoseIndex();
            try
            {                
                data = entity.dgs_HoseIndex.OrderByDescending(d=>d.GetTime).FirstOrDefault();
                if (data != null)
                    status = 1;
            }
            catch (Exception ex)
            {
                status = -1;
                
            }
            context.Response.Write(
                       jsonSerializer.Serialize(
                           new
                           {
                               Status = status,
                               Data=data
                           }
                       )
                   );
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}